package com.example.yang.ministy;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.Toast;

import com.example.yang.ministy.com.example.yang.Fragment.DiscoveryFragment;
import com.example.yang.ministy.com.example.yang.Fragment.MessageFragment;
import com.example.yang.ministy.com.example.yang.Fragment.mefragment;
import com.example.yang.ministy.com.example.yang.Fragment.WonderFragment;

/**
 * Created by Yang on 2016/9/13.
 */
public class MainFrameActivity extends FragmentActivity {
    private RadioGroup navMenu;
    private ImageView ball;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.basketball);
        findView();
        initView();
    }
    private void showFragment(Fragment fragment){
      FragmentTransaction fragmentManager= getSupportFragmentManager().beginTransaction();
        fragmentManager.replace(R.id.fragment_container,fragment);
        fragmentManager.commit();
    }
    public void findView(){
        navMenu=(RadioGroup)findViewById(R.id.rg);
        ball=(ImageView)findViewById(R.id.iv);
    }
    public void initView(){
        navMenu.setOnCheckedChangeListener(checkedChangeListener);
        ball.setOnClickListener(onClickListener);
        showFragment(new WonderFragment());

    }
   RadioGroup.OnCheckedChangeListener checkedChangeListener=new RadioGroup.OnCheckedChangeListener() {
       @Override
       public void onCheckedChanged(RadioGroup group, int checkedId) {
           switch (checkedId){
               case R.id.wonder:
                   showFragment(new WonderFragment());
                   break;
               case R.id.discovery:
                   showFragment(new DiscoveryFragment());
                   break;
               case R.id.message:
                   showFragment(new MessageFragment());
                   break;
               case R.id.me:
                   showFragment(new mefragment());
                   break;
           }
       }
   };

       private View.OnClickListener onClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(MainFrameActivity.this, "点了个球", Toast.LENGTH_SHORT).show();
            }
        };
    }



